package com.example.demo.demos.tools;

import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.client.RestTemplate;

public class HttpUtils {
    private static final RestTemplate restTemplate = new RestTemplate();

    public static ResponseEntity<String> sendPostRequestWithJson(String url, String jsonBody) {
        // 设置请求头部信息
        HttpHeaders headers = new HttpHeaders();
        headers.setContentType(MediaType.APPLICATION_JSON);

        // 创建请求实体对象
        HttpEntity<String> requestEntity = new HttpEntity<>(jsonBody, headers);

        // 发送 POST 请求
        return restTemplate.exchange(url, HttpMethod.POST, requestEntity, String.class);
    }
}